home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / pao / pvs_pvd / src / egbtxt.c next >
Text File  |  1994-06-01  |  16KB  |  560 lines

  1. /* << HighC V1.7 >> [FM-TOWNS] **********************************************
  2. *
  3. *    グラフィック処理(文字表示)
  4. *    ----------------------------------------------------------------------
  5. *    Programmed by Y.Hirata ( NIFTY-ID: NAB03321  パオパオ )
  6. *
  7. *    NOTE: TAB=4
  8. ****************************************************************************/
  9.  
  10. #include <string.h>        /*  strlen,strcpy,memcpy    */
  11. #include <stdarg.h>        /*  va_list,va_*    */
  12. #include <stdio.h>        /*  vsprintf        */
  13. #include <msdos.cf>        /*  getds            */
  14. #include "egbtxt.h"        /*  egb.h,宣言        */
  15.  
  16. char    Gwork[EgbWorkSize] ;                    /*  EGB作業領域            */
  17. int        __gdotx = 8 ;                            /*  文字の横サイズ        */
  18. int        __gdoty = 16 ;                            /*  文字の縦サイズ        */
  19. int        __gdots = 0 ;                            /*  文字間空白ドット数    */
  20. int        __gtype = F_ROM ;                        /*  表示文字種            */
  21. char    __gstrbuf[128] ;                        /*  文字列描画用        */
  22.  
  23. #define    TRUE                1
  24. #define    FALSE                0
  25.  
  26. void pset( int x,int y )
  27. /*===========================================================================
  28. *    点描画
  29. ===========================================================================*/
  30. {
  31.     struct {
  32.         short int    n ;            /*  座標点数    */
  33.         short int    x ;            /*  X座標        */
  34.         short int    y ;            /*  Y座標        */
  35.     } para ;                                    /*  EGB関数用パラメタ        */
  36.  
  37.     para.n = 1 ;
  38.     para.x = x ;
  39.     para.y = y ;
  40.     EGB_pset( Gwork,(char *)¶ ) ;            /*  点描画                */
  41. }
  42.  
  43. void line( int x1,int y1,int x2,int y2 )
  44. /*===========================================================================
  45. *    直線描画
  46. ===========================================================================*/
  47. {
  48.     struct {
  49.         short int    n ;            /*  座標点数    */
  50.         short int    x1, y1 ;    /*  第1点座標    */
  51.         short int    x2, y2 ;    /*  第2点座標    */
  52.     } para ;                                    /*  EGB関数用パラメタ        */
  53.  
  54.     para.n  = 2 ;
  55.     para.x1 = x1 ;
  56.     para.y1 = y1 ;
  57.     para.x2 = x2 ;
  58.     para.y2 = y2 ;
  59.     EGB_connect( Gwork,(char *)¶ ) ;        /*  連続線描画            */
  60. }
  61.  
  62. void triangle( int x1,int y1,int x2,int y2,int x3,int y3 )
  63. /*===========================================================================
  64. *    三角形描画
  65. ===========================================================================*/
  66. {
  67.     struct {
  68.         short int    x1, y1 ;    /*  第1点座標    */
  69.         short int    x2, y2 ;    /*  第2点座標    */
  70.         short int    x3, y3 ;    /*  第3点座標    */
  71.     } para ;                                    /*  EGB関数用パラメタ        */
  72.  
  73.     para.x1 = x1 ;
  74.     para.y1 = y1 ;
  75.     para.x2 = x2 ;
  76.     para.y2 = y2 ;
  77.     para.x3 = x3 ;
  78.     para.y3 = y3 ;
  79.     EGB_triangle( Gwork,(char *)¶ ) ;        /*  三角形描画            */
  80. }
  81.  
  82. void box( int x1,int y1,int x2,int y2 )
  83. /*===========================================================================
  84. *    矩形描画
  85. ===========================================================================*/
  86. {
  87.     struct {
  88.         short int    x1, y1 ;    /*  第1点座標    */
  89.         short int    x2, y2 ;    /*  第2点座標    */
  90.     } para ;                                    /*  EGB関数用パラメタ        */
  91.  
  92.     para.x1 = x1 ;
  93.     para.y1 = y1 ;
  94.     para.x2 = x2 ;
  95.     para.y2 = y2 ;
  96.     EGB_rectangle( Gwork,(char *)¶ ) ;        /*  矩形描画            */
  97. }
  98.  
  99. void ellipse( int x,int y,int dx,int dy )
  100. /*===========================================================================
  101. *    楕円描画
  102. ===========================================================================*/
  103. {
  104.     struct {
  105.         short int    x, y ;        /*  中心点座標    */
  106.         short int    dx, dy ;    /*  X,Y成分        */
  107.     } para ;                                    /*  EGB関数用パラメタ        */
  108.  
  109.     para.x  = x ;
  110.     para.y  = y ;
  111.     para.dx = dx ;
  112.     para.dy = dy ;
  113.     EGB_ellipse( Gwork,(char *)¶ ) ;        /*  楕円描画            */
  114. }
  115.  
  116. void paint( int x,int y,int color )
  117. /*===========================================================================
  118. *    面塗り
  119. ===========================================================================*/
  120. {
  121.     struct {
  122.         short int    x, y ;        /*  X,Y座標    */
  123.     } para ;                                    /*  EGB関数用パラメタ        */
  124.  
  125.     EGB_color( Gwork,C_PAINT,color ) ;            /*  描画色設定            */
  126.     para.x  = x ;
  127.     para.y  = y ;
  128.     EGB_closePaint( Gwork,(char *)¶ ) ;        /*  閉領域塗り潰し        */
  129. }
  130.  
  131. void glocate( int x,int y )
  132. /*===========================================================================
  133. *    テキスト表示位置設定(グラフィック座標)
  134. ===========================================================================*/
  135. {
  136.     struct {
  137.         short int    x, y ;        /*  X,Y座標        */
  138.         short int    len ;        /*  文字列長    */
  139.     } para ;                                    /*  EGB関数用パラメタ        */
  140.  
  141.     para.x   = x ;
  142.     para.y   = y ;
  143.     para.len = 0 ;
  144.     EGB_sjisString( Gwork,(char *)¶ ) ;        /*  文字列の処理        */
  145. }
  146.  
  147. void locate( int clmn,int row )
  148. /*===========================================================================
  149. *    テキスト表示位置設定(テキスト座標)
  150. *    < IN  >    : clmn    桁(1~)
  151. *            : row    行(1~)
  152. ===========================================================================*/
  153. {
  154.     clmn = ( clmn - 1 ) * __gdotx ;                /*  桁→X座標            */
  155.     row  = row * __gdoty - 1 ;                    /*  行→Y座標            */
  156.     glocate( clmn,row ) ;                        /*  描画開始位置        */
  157. }
  158.  
  159. void _gputc( int ch )
  160. /*===========================================================================
  161. *    文字描画(ROMフォント)
  162. ===========================================================================*/
  163. {
  164.     struct {
  165.         short int    len ;
  166.         char    str[2] ;
  167.     } para ;                                    /*  文字列描画用        */
  168.  
  169.     para.len = 1 ;
  170.     para.str[0] = (char)ch ;
  171.     para.str[1] = '\0' ;
  172.     EGB_connectSjisString( Gwork,(char *)¶ ) ;    /*  文字列表示        */
  173. }
  174.  
  175. void _gputs( char *str )
  176. /*===========================================================================
  177. *    文字列描画(ROMフォント)
  178. ===========================================================================*/
  179. {
  180.     struct {
  181.         short int    len ;
  182.         char    str[128] ;
  183.     } para ;                                    /*  文字列描画用        */
  184.  
  185.     para.len = strlen( str ) ;
  186.     strcpy( para.str,str ) ;
  187.     EGB_connectSjisString( Gwork,(char *)¶ ) ;    /*  文字列表示        */
  188. }
  189.  
  190. void _gprintf( char *form,... )
  191. /*===========================================================================
  192. *    書式付文字列描画(ROMフォント)
  193. ===========================================================================*/
  194. {
  195.     va_list    argptr ;
  196.  
  197.     va_start( argptr,form ) ;
  198.     vsprintf( __gstrbuf,form,argptr ) ;
  199.     _gputs( __gstrbuf ) ;
  200.     va_end( argptr ) ;
  201. }
  202.  
  203. void gput( int x1,int y1,int x2,int y2,int pixel,unsigned int ptr )
  204. /*===========================================================================
  205. *    矩形域張り付け
  206. ===========================================================================*/
  207. {
  208.     struct {
  209.         long int    ptr ;        /*  格納アドレス    */
  210.         short int    ds ;        /*  データセレクタ    */
  211.         short int    x1, y1 ;    /*  第1点座標    */
  212.         short int    x2, y2 ;    /*  第2点座標    */
  213.     } para ;                                    /*  EGB関数用パラメタ        */
  214.  
  215.     para.ptr = ptr ;
  216.     para.ds  = getds() ;
  217.     para.x1  = x1 ;
  218.     para.y1  = y1 ;
  219.     para.x2  = x2 ;
  220.     para.y2  = y2 ;
  221.     if ( pixel == 1 )
  222.         EGB_putBlockColor( Gwork,1,(char *)¶ ) ;    /*  単色        */
  223.     else
  224.         EGB_putBlock( Gwork,1,(char *)¶ ) ;            /*  多色        */
  225. }
  226.  
  227. void gget( int x1,int y1,int x2,int y2,unsigned int ptr )
  228. /*===========================================================================
  229. *    矩形域取り込み(多色モード用)
  230. ===========================================================================*/
  231. {
  232.     struct {
  233.         long int    ptr ;        /*  格納アドレス    */
  234.         short int    ds ;        /*  データセレクタ    */
  235.         short int    x1, y1 ;    /*  第1点座標    */
  236.         short int    x2, y2 ;    /*  第2点座標    */
  237.     } para ;                                    /*  EGB関数用パラメタ        */
  238.  
  239.     para.ptr = ptr ;
  240.     para.ds  = getds() ;
  241.     para.x1  = x1 ;
  242.     para.y1  = y1 ;
  243.     para.x2  = x2 ;
  244.     para.y2  = y2 ;
  245.     EGB_getBlock( Gwork,(char *)¶ ) ;
  246. }
  247.  
  248. void convFontY( void )
  249. /*===========================================================================
  250. *    ROMフォントを縦24ドットに加工
  251. ===========================================================================*/
  252. {
  253.     register int    sp, dp ;
  254.     char    wk[32] ;
  255.  
  256.     memcpy( wk,FontData,32 ) ;
  257.     for ( sp=0, dp=0; sp<32; sp+=4, dp+=6 ) {
  258.         FontData[dp+0] = wk[sp] ;
  259.         FontData[dp+1] = wk[sp+1] ;
  260.         FontData[dp+2] = wk[sp+0] | wk[sp+2] ;
  261.         FontData[dp+3] = wk[sp+1] | wk[sp+3] ;
  262.         FontData[dp+4] = wk[sp+2] ;
  263.         FontData[dp+5] = wk[sp+3] ;
  264.     }
  265. }
  266.  
  267. void dispAscii24( int code )
  268. /*===========================================================================
  269. *    ASCII文字表示(縦24ドット)
  270. ===========================================================================*/
  271. {
  272.     register int    off ;
  273.  
  274.     FNT_ankRead( 8,16,code,getds(),FontData ) ;
  275.     for ( off=15; off>=0; off-- ) {
  276.         FontData[off+off+1] = 0 ;
  277.         FontData[off+off] = FontData[off] ;
  278.     }
  279.     convFontY() ;                                /*  ROMフォントを縦24ドットに    */
  280.     EGB_anyChar( Gwork,__gdotx+__gdotx,__gdoty,FontData ) ;
  281.     EGB_textSpace( Gwork,-__gdotx+__gdots ) ;
  282. }
  283.  
  284. void dispSjis24( int sjis )
  285. /*===========================================================================
  286. *    シフトJIS漢字表示(縦24ドット)
  287. ===========================================================================*/
  288. {
  289.     int        code ;
  290.  
  291.     code = FNT_sjisToJis( sjis ) ;
  292.     FNT_kanjiRead( 16,16,code,getds(),FontData ) ;
  293.     convFontY() ;                                /*  ROMフォントを縦24ドットに    */
  294.     EGB_anyChar( Gwork,__gdotx+__gdotx,__gdoty,FontData ) ;
  295.     EGB_textSpace( Gwork,__gdots ) ;
  296. }
  297.  
  298. void gputs24( const char *str )
  299. /*===========================================================================
  300. *    文字列表示(縦24ドット)
  301. ===========================================================================*/
  302. {
  303.     register int    kanji ;
  304.     int        code ;
  305.  
  306.     EGB_textZoom( Gwork,0,8,24 ) ;                /*  ANK        */
  307.     EGB_textZoom( Gwork,1,16,24 ) ;                /*  漢字    */
  308.     while ( *str ) {
  309.         if ( iskanji( *str ) ) {
  310.             code = *str << 8 ;
  311.             str++ ;
  312.             code |= *str ;
  313.             kanji = TRUE ;
  314.         } else {
  315.             code = *str ;
  316.             kanji = FALSE ;
  317.         }
  318.         str++ ;
  319.         if ( kanji ) {                                /*  漢字    */
  320.             dispSjis24( code ) ;
  321.         } else {                                    /*  ANK        */
  322.             dispAscii24( code ) ;
  323.         }
  324.     }
  325.     EGB_textZoom( Gwork,0,__gdotx,__gdoty ) ;            /*  ANK        */
  326.     EGB_textZoom( Gwork,1,__gdotx+__gdotx,__gdoty ) ;    /*  漢字    */
  327.     EGB_textSpace( Gwork,__gdots ) ;
  328. }
  329.  
  330. void gprintf24( char *form,... )
  331. /*===========================================================================
  332. *    書式付文字列描画(縦24ドット)
  333. ===========================================================================*/
  334. {
  335.     va_list    argptr ;
  336.  
  337.     va_start( argptr,form ) ;
  338.     vsprintf( __gstrbuf,form,argptr ) ;
  339.     gputs24( __gstrbuf ) ;
  340.     va_end( argptr ) ;
  341. }
  342.  
  343. void dispAscii( int code )
  344. /*===========================================================================
  345. *    ASCII文字表示(マルチフォント)
  346. ===========================================================================*/
  347. {
  348.     int        off, err=FALSE ;
  349.     FILE    *fp ;
  350.     int        xsize=FontDots, ysize=FontDots ;
  351.  
  352.     if ( xsize == 60 ) xsize = 64 ;
  353.     if ( FontType == 0 || FontType == 1 ) {        /*  全角分    */
  354.         fp = FontFp[2] ;
  355.         off = code * (FontSize+2) ;
  356.     } else {                                    /*  半角分    */
  357.         fp = FontFp[0] ;
  358.         off = code * (FontSize/2) + 16 ;
  359.         xsize >>= 1 ;
  360.         EGB_textZoom( Gwork,1,__gdotx,__gdoty ) ;
  361.     }
  362.     if ( fp == NULL ) {
  363.         err = TRUE ;
  364.     } else {
  365.         if ( off < 0 ) {
  366.             err = TRUE ;
  367.         } else {
  368.             if ( fseek( fp,off,SEEK_SET ) ) {
  369.                 err = TRUE ;
  370.             } else {
  371.                 err = loadFont( fp,code,FALSE ) ;
  372.             }
  373.         }
  374.     }
  375.     if ( err ) {                                /*  ROMフォント                */
  376.         _gputc( code ) ;
  377.         EGB_textSpace( Gwork,__gdots ) ;
  378.     } else {                                    /*  任意フォント            */
  379.         EGB_anyChar( Gwork,xsize,ysize,FontData ) ;
  380.         if ( xsize == 64 ) xsize = 60 ;
  381.         if ( xsize == FontDots ) {                /*  全角分の時            */
  382.             EGB_textSpace( Gwork,-__gdotx+__gdots ) ;    /*  半角分戻す    */
  383.         } else {
  384.             EGB_textSpace( Gwork,__gdots ) ;
  385.         }
  386.     }
  387.     EGB_textZoom( Gwork,1,__gdotx+__gdotx,__gdoty ) ;    /*  漢字    */
  388. }
  389.  
  390. void dispSjis( int sjis )
  391. /*===========================================================================
  392. *    シフトJIS漢字表示(マルチフォント)
  393. ===========================================================================*/
  394. {
  395.     int        off, err=FALSE ;
  396.     int        code ;
  397.     FILE    *fp ;
  398.     char    str[3] ;
  399.     int        xsize=FontDots, ysize=FontDots ;
  400.  
  401.     if ( xsize == 60 ) xsize = 64 ;
  402.     fp = FontFp[0] ;
  403.     code = sjis ;
  404.     off = getFontOffset( &code ) ;                /*  格納位置取得        */
  405.     if ( fp == NULL ) {
  406.         err = TRUE ;
  407.     } else {
  408.         if ( off < 0 ) {
  409.             err = TRUE ;
  410.         } else {
  411.             if ( fseek( fp,off,SEEK_SET ) ) {
  412.                 err = TRUE ;
  413.             } else {
  414.                 err = loadFont( fp,code,TRUE ) ;
  415.             }
  416.         }
  417.     }
  418.     if ( err ) {
  419.         str[0] = (char)( sjis >> 8 ) ;
  420.         str[1] = (char)( sjis & 0xFF ) ;
  421.         str[2] = '\0' ;
  422.         _gputs( str ) ;
  423.     } else {
  424.         EGB_anyChar( Gwork,xsize,ysize,FontData ) ;
  425.     }
  426.     EGB_textSpace( Gwork,__gdots ) ;
  427. }
  428.  
  429. void gputs2( const char *str )
  430. /*===========================================================================
  431. *    マルチフォント文字列表示
  432. ===========================================================================*/
  433. {
  434.     int        kanji ;
  435.     int        code ;
  436.  
  437.     while ( *str ) {
  438.         if ( iskanji( *str ) ) {
  439.             code = *str << 8 ;
  440.             str++ ;
  441.             code |= *str ;
  442.             kanji = TRUE ;
  443.         } else {
  444.             code = *str ;
  445.             kanji = FALSE ;
  446.         }
  447.         str++ ;
  448.         if ( kanji ) {                            /*  漢字    */
  449.             dispSjis( code ) ;
  450.         } else {                                /*  ANK        */
  451.             dispAscii( code ) ;
  452.         }
  453.     }
  454.     EGB_textSpace( Gwork,__gdots ) ;
  455. }
  456.  
  457. void gprintf2( char *form,... )
  458. /*===========================================================================
  459. *    書式付文字列描画(マルチフォント)
  460. ===========================================================================*/
  461. {
  462.     va_list    argptr ;
  463.  
  464.     va_start( argptr,form ) ;
  465.     vsprintf( __gstrbuf,form,argptr ) ;
  466.     gputs2( __gstrbuf ) ;
  467.     va_end( argptr ) ;
  468. }
  469.  
  470. void setTextSpace( int size )
  471. /*===========================================================================
  472. *    文字間空白のドット数設定
  473. ===========================================================================*/
  474. {
  475.     __gdots = size ;
  476.     EGB_textSpace( Gwork,__gdots ) ;            /*  文字間空白設定        */
  477. }
  478.  
  479. void setTextSize( int xsize,int ysize )
  480. /*===========================================================================
  481. *    文字サイズ設定
  482. *    < IN  >    : xsize    ANKの横サイズ(倍値を漢字の横サイズとする)
  483. *            : ysize    ANK/漢字の縦サイズ
  484. ===========================================================================*/
  485. {
  486.     __gdotx = xsize ;
  487.     __gdoty = ysize ;
  488.     EGB_textZoom( Gwork,0,__gdotx,__gdoty ) ;            /*  ANK        */
  489.     EGB_textZoom( Gwork,1,__gdotx+__gdotx,__gdoty ) ;    /*  漢字    */
  490. }
  491.  
  492. void setTextType( int type )
  493. /*===========================================================================
  494. *    表示文字種の設定
  495. *    マルチフォント指定時は, fotnOpen関数をcallする必要あり
  496. ===========================================================================*/
  497. {
  498.     switch ( type ) {
  499.     case F_ROM24:
  500.     case F_FILE    :    __gtype = type ;        break ;
  501.     case F_ROM    :
  502.     default        :    __gtype = F_ROM ;
  503.     }
  504. }
  505.  
  506. void gputc( int ch )
  507. /*===========================================================================
  508. *    文字描画
  509. ===========================================================================*/
  510. {
  511.     switch ( __gtype ) {
  512.     case F_ROM24:
  513.         EGB_textZoom( Gwork,0,8,24 ) ;                        /*  ANK        */
  514.         EGB_textZoom( Gwork,1,16,24 ) ;                        /*  漢字    */
  515.         dispAscii24( ch ) ;
  516.         EGB_textZoom( Gwork,0,__gdotx,__gdoty ) ;            /*  ANK        */
  517.         EGB_textZoom( Gwork,1,__gdotx+__gdotx,__gdoty ) ;    /*  漢字    */
  518.         break ;
  519.     case F_FILE    :
  520.         dispAscii( ch ) ;
  521.         break ;
  522.     case F_ROM    :
  523.     default        :
  524.         _gputc( ch ) ;
  525.     }
  526.     EGB_textSpace( Gwork,__gdots ) ;
  527. }
  528.  
  529. void gputs( char *str )
  530. /*===========================================================================
  531. *    文字列描画
  532. ===========================================================================*/
  533. {
  534.     switch ( __gtype ) {
  535.     case F_ROM24:    gputs24( str ) ;    break ;
  536.     case F_FILE    :    gputs2( str ) ;        break ;
  537.     case F_ROM    :
  538.     default        :    _gputs( str ) ;
  539.     }
  540. }
  541.  
  542. void gprintf( char *form,... )
  543. /*===========================================================================
  544. *    書式付文字列描画
  545. ===========================================================================*/
  546. {
  547.     va_list    argptr ;
  548.  
  549.     va_start( argptr,form ) ;
  550.     vsprintf( __gstrbuf,form,argptr ) ;
  551.     gputs( __gstrbuf ) ;
  552.     va_end( argptr ) ;
  553. }
  554.  
  555. /*    HISTORY
  556. -----------------------------------------------------------------------------
  557. *    1991.04.13 : CREATE
  558. *    1993.08.09 : remake
  559. ---------------------------------------------------------------------------*/
  560.